import React, { Component } from 'react';
import { Text, View, ScrollView, KeyboardAvoidingView, Platform, PixelRatio, Image, TouchableOpacity, Alert } from "react-native";
import MethodUtil from '../../../utils/MethodUtil';
import { GLOBAL } from '../../../config/global';
import { style } from '../../../theme/style';
import { SelectComponent } from './_components/SelectComponent';
import { AddLongBtn } from './_components/AddLongBtn.js';
import { Common } from '../../../component/common/Common.js';
import { TitleView } from './_components/TitleView.js';
import { HalfList } from './_components/HalfList.js';
import { PageStatusIndex } from '../../../component/page-status/PageStatusIndex';
const scale = GLOBAL.SCALE;
import { StackActions } from 'react-navigation';
import { CURRENCY } from '../../../utils/helper';
import { GET_R_TITLE_NAME, GET_R_FLAG, } from '../../../config/definition';
import OrderAPIService from './_common/OrderAPIService';
import OrderCreactService from './_common/service';
import { orderFormStyle, toggleBtnStyle } from './_common/style'
import ToastUtil from '../../../utils/toast';
import Dictionary from '../../../utils/dictionary';
import { AddressComponent } from './_components/AddressComponent.js';

/*
*orderType  销售->S   采购->P
*periodType 长约->L   普通->S
*tCode   现货->S   长约->L  远期->F   代理->A   E->长约执行  C->背靠背  QH ->泉化
*oppoOrderId  闭口的第一步采购订单号
*oppoDeliveryType  第二步的 交货方式
*/
let timer = null;
let statusOff = require('../../../imgs/apply/statusOff.png');
let statusOn = require('../../../imgs/apply/statusOn.png');
let titleImgObj = require('../../../imgs/global/query.png');
let arrowImg = require('../../../imgs/arrowBlue.png')
export class OrderBaseInfoPage extends Component {
	static navigationOptions = {
		header: null
	}
	requesting;
	constructor(props) {
		super(props);
		this.sendData = { currency: 'RMB' };
		this.jumpPage = OrderCreactService.jump.bind(this);
		this.state = {
			tradeType: 'I',// 交易类型 
			isUnite: '0',// 业务类型 
			agencyCompanyName: '请选择',//代理供应商名称
			companyName: '请选择',	//供应商名称

			payTypeValue: '请选择',
			payTypeIndex: -1,

			payMethodIndex: -1,
			payMethodValue: '请选择',
			payTypeArr: [],// 付款方式后  输入 

			//外贸付款方式
			outOrderPayMethodList: [],
			currPayMethodIndex: 0,//当前列表选中项
			currOutPayMethodListIndex: -1,

			deliveryValue: '请选择',
			deliveryIndex: -1,

			lossValue: '请选择',//运损承担方
			lossIndex: -1,

			disputeValue: '请选择',
			disputeIndex: -1,

			priceTermsValue: '请选择',
			priceTermsIndex: -1,

			lostRateIndex: -1,

			status: 'data',
			isLostRate: true,  // 控制涂损率

			deliveryTypeIsX: false,//长约执行 交货方式为其他
			trustShow: false,//是否显示授信
			modalObj: {
				currSelectIndex: -1,
				currTitle: '',
				currlistData: [],
				currCb: null,
				currIsVisible: false
			},

			//长约执行数据
			onShow: false,
			deliveryTypeIsX: false,//长约执行 交货方式为其他
			pageEdit: false,

			transportTypeIndex: -1,// 运输方式
			transportTypeValue: '请选择',
		}
		this.isfirstToggle = true;
		this.tradeTypeData = []    // 交易类型 
		this.businessTypeData = []    // 业务类型 
		this.payTypeData = []//当前付款方式
		this.inPayTypeData = []  // 内贸付款类型
		this.outPayTypeData = []// 外贸付款类型
		this.payMethodData = []  //付款方式
		this.outPayMethodData = []//外贸付款方式
		this.lossData = []//运损承担方
		this.deliveryData = [];//交货方式
		this.priceTermsData = [];//价格条款
		this.lostRateData = [];//途损率
		this.transportTypeData = []; // 运输方式

		this.deliveryAddressList = []; // 出库地
		this.endAddressList = []; // 目的地
		// 展示数据
		this.showData = {
			limitAmount: '',
			creditEndDate: '',
			isExpired: null
		}
		this.data = {
			pushIndex: -1,
		}
		this.orderFlag = {}
		this.PageText = {}
		this.editData = {}
		this.accountDay = ''
		this.isVerify = {
			startAddress: null,
			endAddress: null,
			trans: null
		}
	}

	async componentWillMount () {
		this.setState({
			status: 'loading'
		})
		this.sendData.tradeType = 'I';  // 初始化 交易类型
		this.sendData.isUnite = '0';  // 初始化 业务类型
		await this.initData();
		this.setState({
			status: 'data'
		})
	}

	checkCompany () {
		if (!this.sendData.companyId) {
			ToastUtil.showWarning(`请先选择${this.PageText.company}`);
			return false
		}
		return true
	}

	//获取默认代理供应商
	async getDefaultSupplier () {
		let supplierData = await OrderAPIService.getSupplier();
		if (supplierData.rows && supplierData.rows.length > 0) {
			this.sendData.agencyCompanyId = supplierData.rows[0].companyId;
			this.setState({ agencyCompanyName: supplierData.rows[0].companyName })
		}
	}

	//获取数据库字典
	async getDictList () {
		let { orderType, tCode } = this.orderFlag;
		let deliveryTypeDic = orderType == 'P' ? 'EC_PURCHASE_DELIVERY_TYPE' : 'EC_SALES_DELIVERY_TYPE';
		let businessTypeDic = orderType == 'P' ? 'ORDER_PURCHASE_UNITE_FLAG' : 'ORDER_SALE_UNITE_FLAG';
		if (tCode === 'C') {
			deliveryTypeDic = 'EC_OPPO_DELIVERY_TYPE';
		}
		this.tradeTypeData = await Dictionary.get('EC_TRADE_TYPE');   // 交易类型 
		this.businessTypeData = await Dictionary.get(businessTypeDic);   // 业务类型 销售 
		this.inPayTypeData = await Dictionary.get('EC_PAY_TYPE'); // 付款类型
		this.QHPayTypeData = await Dictionary.get('EC_QH_PAY_TYPE');
		this.outPayTypeData = await Dictionary.get('EC_LONG_OUT_PAY_TYPE');// 外贸付款类型
		if (tCode === 'QH') {
			this.payTypeData = this.QHPayTypeData;
		} else {
			this.payTypeData = this.inPayTypeData;
		}
		this.payMethodData = await Dictionary.get('EC_PAY_METHOD'); //付款方式
		this.outPayMethodData = await Dictionary.get('EC_OUT_TRADE_PAY_METHOD');//外贸付款方式
		this.lossData = await Dictionary.get('EC_OD_LOST_RENDER');//运损承担方
		this.deliveryData = await Dictionary.get(deliveryTypeDic);//交货方式
		this.priceTermsData = await Dictionary.get('EC_OT_DELIVERY_TYPE');//价格条款
		this.lostRateData = await Dictionary.get('LOST_RENDER_TYPE');//途损率
		this.transportTypeData = await Dictionary.get('EC_TRANSPORT_TYPE');//运输方式
	}

	//初始化数据
	async initData () {
		let { pageEdit, orderType, periodType, tCode, orderId, oppoOrderId, longOrderId, isAgency, bizMode, isFuture, currStep, isQhXhXsBiz } = this.props.navigation.state.params;
		console.log('第一步初始化', this.props.navigation.state.params)
		currStep = currStep || 1;
		tCode = tCode || this.getTCode(isAgency, bizMode, periodType, isFuture, longOrderId, isQhXhXsBiz);
		this.sendData.logisticsPrice = '0' // 运费单价默认为0
		if (orderId) {
			if (tCode == 'C') {
				orderType = currStep == 1 ? 'P' : 'S';
				if (currStep == 1) {
					this.sendData.orderId = oppoOrderId;
				} else {
					this.sendData.orderId = orderId;
					this.sendData.oppoOrderId = oppoOrderId;
				}
				if (currStep == 2) {
					this.setState({ pageEdit });
				} else {
					this.setState({ pageEdit: true });
				}
			} else {
				this.sendData.orderId = orderId;
				this.sendData.oppoOrderId = oppoOrderId;
			}
			OrderAPIService.initAPIs(tCode, orderType)
			await this.initOrderFlag(orderType, periodType, tCode, currStep);
			await this.editInit(this.sendData.orderId);
		} else {
			if (tCode === 'C') {
				this.sendData.oppoOrderId = oppoOrderId;//创建闭口第二步
				periodType = 'S';
				orderType = currStep == 1 ? 'P' : 'S';
			}
			OrderAPIService.initAPIs(tCode, orderType)
			await this.initOrderFlag(orderType, periodType, tCode, currStep);
			this.sendData.lostRateBig = '3';//途损率默认千分之3
			this.sendData.contractStandard = 1;//途损率默认千分之3
			this.lossCallBack(1);//运损承担方默认对方
			if (tCode === 'L') {
				this.operateOutPayMethodList();
			}
			if (tCode === 'A') {
				await this.getDefaultSupplier();
			}
		}
	}

	//初始化-订单标识-orderType, periodType, tCode, currStep
	async	initOrderFlag (orderType, periodType, tCode, currStep) {
		this.orderFlag.orderType = orderType;
		this.orderFlag.periodType = periodType;
		this.orderFlag.tCode = tCode;
		this.orderFlag.currStep = currStep;
		this.orderFlag.titleName = GET_R_TITLE_NAME(orderType, tCode);
		this.initPageText();
		let flagObj = GET_R_FLAG(tCode);
		this.orderFlag.flagObj = flagObj;
		this.sendData = { ...this.sendData, ...flagObj };
		await this.getDictList();
	}

	getTCode = (isAgency, bizMode, periodType, isFuture, longOrderId, isQuanHua) => {
		let tCode = 'S';//现货
		if (isAgency == 1) { tCode = 'A' };//代理
		if (bizMode == 1) { tCode = 'C' };//闭口
		if (periodType == 'L') { tCode = 'L' };//长约框架
		if (isFuture == 1) { tCode = 'F' };//远期
		if (longOrderId) { tCode = 'E' };//执行
		if (isQuanHua === 'Y') { tCode = 'QH' };//泉化销售单
		return tCode;
	}

	initPageText = () => {
		if (this.orderFlag.orderType === 'P') {
			this.PageText.company = '供应商';
			this.PageText.payType = '付款类型';
			this.PageText.payMethod = '付款方式';
		} else {
			this.PageText.company = '客户';
			this.PageText.payType = '收款类型';
			this.PageText.payMethod = '收款方式';
		}
	}

	//地址回显
	_longAdd = () => {
		let { transportTypeData } = this;
		let { srcAddressId, destAddressId, srcAddress, destAddress, transportType } = this.editData;
		//运输方式
		transportTypeData.map((item, index) => {
			if (item.dictKey == transportType) {
				this.setState({
					transportTypeIndex: index,
					transportTypeValue: item.dictName
				})
			}
		})

		//交货地
		if (srcAddressId) {  // 出库地
			this.deliveryAddressList.push({ addrId: srcAddressId, addressName: srcAddress })
		}
		if (destAddressId) { //目的地
			this.endAddressList.push({ addrId: destAddressId, addressName: destAddress })
		}
	}

	//初始化-编辑-state
	initPageData = () => {
		let { tradeType, isUnite, companyName, agencyCompanyName, payType, deliveryType, oppoDeliveryType, lostRender, payStyle, priceTerm, outOrderPayMethodList, contractStandard, lostRateBig,
			transportType, srcAddressId, destAddressId, srcAddress, destAddress
		} = this.editData;
		let { deliveryData, lossData, payTypeData, payMethodData, priceTermsData, lostRateData, transportTypeData } = this;
		outOrderPayMethodList && outOrderPayMethodList.map(item => {
			item.prepayRateShow = MethodUtil.countObj.multiply(item.prepayRate, 100);
			if (OrderCreactService.isNeedPaymentDays(item.payMethodName)) {
				item.isPayMethodDays = true;
			}
		})
		let indexObj = {
			isLostRate: true,
			tradeType,
			isUnite,
			outOrderPayMethodList,//外贸付款方式
			agencyCompanyName,
			companyName,
			transportType,  // 运输方式
		};
		//闭口销售交货方式转换
		if (this.orderFlag.currStep == 2 && this.orderFlag.tCode === 'C') {
			deliveryType = oppoDeliveryType;
			this.sendData.oppoDeliveryType = oppoDeliveryType;
		} else {
			//页面是否编辑状态
			indexObj.pageEdit = true
		}

		//运输方式
		transportTypeData.map((item, index) => {
			if (item.dictKey == transportType) {
				indexObj.transportTypeIndex = index;
				indexObj.transportTypeValue = item.dictName;
			}
		})

		//交货地
		this.deliveryAddressList = [];
		this.endAddressList = [];
		if (srcAddressId) {  // 出库地
			this.deliveryAddressList.push({ addrId: srcAddressId, addressName: srcAddress })
		}
		if (destAddressId) { //目的地
			this.endAddressList.push({ addrId: destAddressId, addressName: destAddress })
		}


		// 付款方式
		payMethodData.map((item, index) => {
			if (item.dictKey == payStyle) {
				indexObj.payMethodIndex = index;
				indexObj.payMethodValue = item.dictName;
			}
		})

		// 交货方式
		deliveryData.map((item, index) => {
			if (item.dictKey == deliveryType) {
				indexObj.deliveryIndex = index;
				indexObj.deliveryValue = item.dictName;
				indexObj.isLostRate = deliveryType == 'U' || deliveryType == 'Y' ? false : true;
			}
		})

		// 运损承担方
		lossData.map((item, index) => {
			if (item.dictKey == lostRender) {
				indexObj.lossIndex = index;
				indexObj.lossValue = item.dictName;
			}
		})

		// 付款类型
		payTypeData.map((item, index) => {
			if (item.dictKey == payType) {
				indexObj.payTypeIndex = index;
				indexObj.payTypeValue = item.dictName;
				indexObj.payTypeArr = this.payTypeInit(payType);
			}
		})

		//价格条款
		priceTermsData.map((item, index) => {
			if (item.dictKey == priceTerm) {
				indexObj.priceTermsIndex = index;
				indexObj.priceTermsValue = item.dictName;
			}
		})

		//途损率 lostRateIndex
		if (contractStandard == 0) {
			indexObj.lostRateIndex = 0
		} else {
			lostRateData.map((item, index) => {
				if (item.dictName == lostRateBig) {
					indexObj.lostRateIndex = index
				}
			})
		}

		return indexObj;
	}

	//初始化-编辑-sendData
	initSendData = () => {
		let { orderId, oppoOrderId, longOrderId, tradeType, isUnite, companyId, agencyCompanyId, payType, contractStandard,
			baseDateSettle, deliveryType, lostRender, lostRateBig, payStyle, priceTerm, remark, auditRemark, currency,
			transportType, srcAddressId, destAddressId } = this.editData;
		let tempSendData = {
			orderId,
			oppoOrderId,
			longOrderId,
			tradeType, // 交易类型
			isUnite, //业务类型
			agencyCompanyId,//代理供应商
			companyId,//供应商
			baseDateSettle, // 结算基准日期
			deliveryType,// 交货方式
			lostRender,//运损承担方
			payType,//付款类型
			payStyle,//付款方式
			lostRateBig,// 途损率
			remark,//合同备注
			auditRemark,//送审备注
			currency,//币种
			priceTerm,//价格条款
			contractStandard,//是否标准合同
			transportType,// 运输方式
			srcAddressId, // 出库地
			destAddressId, //目的地
		}
		this.sendData = { ...this.sendData, ...tempSendData };
		//付款类型-授信初始化
		console.log('payType', payType)
		this.initTrust(payType)
	}

	//付款类型-授信初始化
	async	initTrust (payType) {
		await this.trustFn();
		this.setState({ trustShow: this.judgeTrust(payType) })
	}

	// 初始化 - 编辑
	async	editInit (orderId, isChooseLong) {
		this.editData = await OrderAPIService.getOrderDetail({ orderId, queryType: 'ORDER_ALL_INFO' }) || {};
		console.log('编辑数据回显', this.editData)
		let { lostRate, tradeType } = this.editData;
		//长约执行
		let { tCode, flagObj } = this.orderFlag;

		this.payTypeData = tCode === 'QH' ? this.QHPayTypeData : tradeType === 'O' ? this.outPayTypeData : this.inPayTypeData;
		this.editData.lostRateBig = MethodUtil.countObj.multiply(lostRate, 1000);// 途损率
		this.sendData.logisticsPrice = this.editData.logisticsPrice || '0' // 运费单价默认为0
		if (tCode === 'E' || tCode === 'QH' || isChooseLong) {
			this.sendData = { ...this.editData, ...flagObj };
			this._longAdd();
			let { outOrderPayMethodList } = this.sendData;
			outOrderPayMethodList && outOrderPayMethodList.map(item => {
				item.prepayRateShow = MethodUtil.countObj.multiply(item.prepayRate, 100);
			})
			let deliveryTypeIsX = false;
			//选择长约执行
			if (isChooseLong) {
				this.sendData.orderId = '';
				this.sendData.orderNo = null;
				this.sendData.contractId = null;
				this.sendData.contractNo = null;
				this.sendData.longOrderId = orderId;
				this.sendData.longDeliveryType = this.sendData.deliveryType;
				if (this.sendData.deliveryType === 'X') this.sendData.deliveryType = '';
			}
			if (this.sendData.longDeliveryType === 'X') deliveryTypeIsX = true;

			let deliveryIndex = -1;
			this.deliveryData.map((item, index) => {
				if (item.dictKey === this.sendData.deliveryType) deliveryIndex = index;
			})

			if (tCode === 'QH') {
				let responseData = await OrderAPIService.getCustomerFunds({ companyId: this.sendData.companyId, currency: this.sendData.currency }) || {};
				this.sendData.funds = responseData.value;
				// this.sendData.priceFormulaType =='PRICE_013' 现货价
				// if (this.sendData.priceFormulaType === 'PRICE_013') {
				// let dateStr = moment().format('YYYY-MM-DD') + ' 19:00:00';
				// this.sendData.exeEndDate = this.sendData.exeEndDate || moment(dateStr).format('YYYY-MM-DD HH:mm:ss');
				// this.sendData.exeEndDateShow = moment(this.sendData.exeEndDate).format('YYYY-MM-DD HH:mm');
				// }
			}

			this.setState({ onShow: true, deliveryIndex, deliveryTypeIsX, payTypeArr: this.payTypeInit(this.editData.payType) });
			return;
		};
		let pageData = this.initPageData();
		this.setState({ ...pageData }, () => {
			this.initSendData()
		}
		)
	}

	// 付款类型初始化
	payTypeInit = (dictKey) => {
		let payTypeArr = [];
		this.payTypeData.map(item => {
			if (item.dictKey == dictKey && item.comments) {
				payTypeArr = eval(item.comments);
				return;
			}
		})

		payTypeArr.forEach((item) => {
			if (this.orderFlag.tCode === 'E') {
				item.value = this.sendData[item.name];
			} else {
				item.value = this.editData[item.name];
				this.sendData[item.name] = this.editData[item.name];
			}
		})
		return payTypeArr;
	}

	//付款类型-是否授信初始化
	judgeTrust = (payType) => {
		let trustShow = false
		let { orderType, tCode } = this.orderFlag;
		//长约执行与长约框架 没有授信
		// if (tCode === 'L' || tCode === 'E') {
		// 	return
		// }

		/*采购:保证金/定金  款到发货
		  销售:货到付款  票到付款*/
		if (orderType == 'P') {
			if (payType == '2' || payType == '4') {
				trustShow = true;
			}
		} else if (orderType == 'S') {
			if (payType == '3' || payType == '5') {
				trustShow = true;
			}
		}
		return trustShow
	}

	//授信初始化
	async trustFn () {
		let trustSend = {
			companyId: this.sendData.companyId,
			corpType: this.orderFlag.orderType == 'P' ? '1' : '2',
			orderType: this.orderFlag.orderType
		}
		let trustData = await OrderAPIService.orderTrust(trustSend);
		console.log('trustData-授信初始化', trustData)
		if (trustData) {
			let { limitAmount, creditEndDate, accountDay, isExpired } = trustData;
			this.showData.limitAmount = limitAmount || '';
			this.showData.creditEndDate = creditEndDate || '';
			this.showData.isExpired = isExpired || '0';
			this.accountDay = accountDay;
		}
	}

	// 下一步的点击按钮事件 
	async	submitData () {
		if (this.requesting) return;
		if (!this.isValidatePass()) return;
		let subData = this.getAllParams();
		this.setState({
			status: 'loading'
		})
		this.requesting = true;
		console.log('subData-对比', subData)
		let saveData = await OrderAPIService.orderAdd(subData);
		this.setState({
			status: 'data'
		})

		if (saveData) {
			setTimeout(() => {
				this.requesting = false;
			}, 1000)
			if (!this.sendData.orderId) this.sendData.orderId = saveData.orderId;
			this.setState({ refresh: true });
			this.nextStep(saveData);
		} else {
			this.requesting = false;
		}
	}

	//保存订单成功 后续
	nextStep = (saveData) => {
		console.log('第一步提交回来的数据-后续', saveData)
		let { tCode, currStep } = this.orderFlag;
		let params = {
			...this.orderFlag,
		}

		params.orderPlanNotCheckFlag = saveData.orderPlanNotCheckFlag || null;

		//长约执行需要关联长约框架id
		if (tCode === 'E' || tCode === 'QH') {
			params.longOrderId = saveData.longOrderId;
		};

		if (tCode === 'C' && currStep == 2) {
			let { companyIdBuy, companyNameBuy } = this.props.navigation.state.params;
			params.companyIdBuy = companyIdBuy;
			params.companyNameBuy = companyNameBuy;
			params.titleName = '闭口销售成交报告';
			params.deliveryType = saveData.oppoDeliveryType// 交货方式   后面交货地址要用
		} else {
			params.deliveryType = saveData.deliveryType;// 交货方式   后面交货地址要用
			console.log('第一步可能走', params.deliveryType)
		}

		//闭口第一步
		if (tCode === 'C' && currStep == 1) {
			params.currStep = 2;
			params.bizMode = 1;
			params.oppoOrderId = saveData.orderId;
			params.companyIdBuy = saveData.companyId; // 企业,供应商  id
			params.companyNameBuy = saveData.companyName;
			params.orderId = saveData.oppoOrderId;
			params.pageEdit = this.state.pageEdit;
			const pushAction = StackActions.push({
				routeName: 'OrderBaseInfoPage',
				params
			});
			this.props.navigation.dispatch(pushAction);
			return;
		}
		params.priceType = saveData.priceType;
		params.baseDateSettleName = saveData.baseDateSettleName;
		params.baseDateSettle = saveData.baseDateSettle;
		if (this.orderFlag.tCode === 'C') {
			params.priceType = this.sendData.priceType;
		}
		params.orderId = saveData.orderId;
		params.companyId = saveData.companyId; // 企业,供应商  id
		params.companyName = saveData.companyName;
		params.agencyCompanyId = saveData.agencyCompanyId;
		params.agencyCompanyName = saveData.agencyCompanyName;
		params.oppoOrderId = saveData.oppoOrderId;
		params.currency = saveData.currency;
		params.tradeType = saveData.tradeType;
		params.isUnite = saveData.isUnite;
		params.logisticsPrice = saveData.logisticsPrice;
		let page = this.orderFlag.tCode === 'QH' ? 'QHOrderGoodsInfoPage' : 'OrderGoodsInfoPage';
		console.log('下一步传递的数据', params, page)
		this.props.navigation.navigate(page, params)
	}

	//赋值提交数据
	getAllParams = () => {
		let { tCode, currStep, orderType, periodType } = this.orderFlag;
		let subData = {};
		let { outOrderPayMethodList } = this.sendData;

		//清除未填写的付款方式
		outOrderPayMethodList && outOrderPayMethodList.map(item => {
			if (item.payMethod) {
				item.prepayRate = MethodUtil.countObj.divide(item.prepayRateShow, 100, 2);
			}
		})

		subData.orderInfo = this.sendData;

		//闭口成交
		if (tCode === "C" && currStep == 2) {
			subData.orderInfo.oppoLostRender = subData.orderInfo.lostRender;
			//subData.orderInfo.oppoDeliveryType = subData.orderInfo.deliveryType;222222
		}

		subData.submitStep = 'ADD_ORDER_BASE_INFO';
		subData.orderInfo.orderType = orderType;
		subData.orderInfo.periodType = periodType;
		console.log('提交数据', subData)
		return subData;
	}

	//验证是否通过
	isValidatePass = () => {
		let { transportType, srcAddressId, destAddressId } = this.sendData;
		//长约执行
		if (this.orderFlag.tCode === 'E' || this.orderFlag.tCode === 'QH') {
			if (!this.sendData.longOrderId) {
				ToastUtil.showWarning(`请选择${this.PageText.company}`)
				return false
			}
			if (!this.sendData.deliveryType) {
				ToastUtil.showWarning('请先选择交货方式')
				return false
			}
			if (this.sendData.payType == '2' && Number.parseFloat(this.sendData.prepayRate) <= 0) {
				ToastUtil.showWarning(`保证金/定金比例必须大于0`);
				payTypeArrPass = false;
				return;
			}

			//交货地验证
			if (this.isVerify.startAddress && !srcAddressId) {
				ToastUtil.showWarning('请先选择出库地');
				return false;
			}
			if (this.isVerify.endAddress && !destAddressId) {
				ToastUtil.showWarning('请先选择目的地');
				return false;
			}
			//运输方式
			if (this.isVerify.trans && !transportType) {
				ToastUtil.showWarning('请先选择运输方式');
				return false;
			}

			//代理销售
		} else if (this.orderFlag.tCode === 'A' && !this.sendData.agencyCompanyId) {
			ToastUtil.showWarning('请先选择供应商');
			return false
		} else {
			if (!this.validateParams()) {
				return false
			}
		}
		return true;
	}

	//验证通用成交报告字段
	validateParams = () => {
		let { isLostRate, payTypeArr } = this.state;
		this.sendData.outOrderPayMethodList = this.state.outOrderPayMethodList;
		let { tradeType, isUnite, companyId, payType, outOrderPayMethodList, payStyle,
			deliveryType, lostRateBig, lostRender, priceTerm, transportType, srcAddressId, destAddressId } = this.sendData;

		//交易类型-验证
		if (!tradeType) {
			ToastUtil.showWarning('请选择交易类型');
			return false;
		}
		//供应商-验证
		if (!companyId) {
			ToastUtil.showWarning(`请选择${this.PageText.company}`);
			return false;
		}
		//付款类型-验证
		if (!payType) {
			ToastUtil.showWarning(`请选择${this.PageText.payType}`);
			return false;
		} else if (tradeType !== 'O') {
			let payTypeArrPass = true;
			payTypeArr && payTypeArr.map(item => {
				if (!this.sendData[item.name]) {
					ToastUtil.showWarning(`请先填写完整${this.PageText.payType}相关数据`);
					payTypeArrPass = false;
					return;
				}

				if (this.sendData.payType == '2' && Number.parseFloat(this.sendData.prepayRate) <= 0) {
					ToastUtil.showWarning(`保证金/定金比例必须大于0`);
					payTypeArrPass = false;
					return;
				}

				if (this.orderFlag.orderType === 'P' && item.name === 'deliveryExpireDays') {
					if (Number.parseFloat(this.sendData[item.name]) > Number.parseFloat(this.accountDay)) {
						ToastUtil.showWarning(`本单授信账期必须小于等于授信账户账期天数`);
						payTypeArrPass = false;
						return;
					}
				}
				if (this.orderFlag.orderType === 'S' && item.name === 'payExpireDays') {
					if (Number.parseFloat(this.sendData[item.name]) > Number.parseFloat(this.accountDay)) {
						ToastUtil.showWarning(`付款天数必须小于等于账期天数`);
						payTypeArrPass = false;
						return;
					}
				}
			})
			if (!payTypeArrPass) return payTypeArrPass
		}

		//付款方式-验证
		if (tradeType === 'O') {
			//长约框架外贸  付款方式-验证
			if (outOrderPayMethodList.length < 1) {
				ToastUtil.showWarning('请先选择付款方式');
				return false;
			} else {
				let pass = true;
				let totalPrepayRate = 0;
				outOrderPayMethodList.map(item => {
					totalPrepayRate += Number.parseFloat(item.prepayRateShow);
					if (!item.prepayRateShow) {
						ToastUtil.showWarning('请填写付款比例');
						pass = false;
					}
					//付款期限-验证
					if (item.isPayMethodDays && !item.payExpireDays) {
						ToastUtil.showWarning('请填写付款期限');
						pass = false;
					}
				})
				if (totalPrepayRate !== 100) {
					pass = false;
					ToastUtil.showWarning('付款比例总和必须等于100%');
				}
				if (!pass) return pass;
			}

			//价格条款
			if (!priceTerm) {
				ToastUtil.showWarning('请选择价格条款');
				return false;
			}
		} else {
			if (!payStyle) {
				ToastUtil.showWarning(`请选择${this.PageText.payMethod}`);
				return false;
			}
		}

		if (this.orderFlag.tCode === 'C' && this.orderFlag.currStep === 1) {
			return true;
		}
		//交货方式-验证
		if (!deliveryType) {
			ToastUtil.showWarning('请先选择交货方式');
			return false;
		}

		//交货地验证
		if (this.isVerify.startAddress && !srcAddressId) {
			ToastUtil.showWarning('请先选择出库地');
			return false;
		}
		if (this.isVerify.endAddress && !destAddressId) {
			ToastUtil.showWarning('请先选择目的地');
			return false;
		}
		//运输方式
		if (this.isVerify.trans && !transportType) {
			ToastUtil.showWarning('请先选择运输方式');
			return false;
		}


		if (isLostRate) {
			//运损承担方-验证
			if (!lostRender) {
				ToastUtil.showWarning('请先选择运损承担方');
				return false;
			}

			//途损率-验证
			if (!lostRateBig && lostRateBig !== 0 && lostRateBig !== '0') {
				ToastUtil.showWarning('请输入途损率');
				return false;
			}
		}

		if (isLostRate) {
			this.sendData.lostRate = MethodUtil.countObj.divide(lostRateBig, 1000, 4);
		}

		return true;
	}

	//顶部关闭按钮
	_headCloes = () => {
		this.props.navigation.goBack();
	}

	// 渲染地址封装
	_renderAddressSelect = (text, addressList, addressListStr, addressType, isOk) => {
		if (text == '出库地') {
			this.isVerify.startAddress = true;
		} else {
			this.isVerify.endAddress = true;
		}
		return (
			<AddressComponent
				addBtnText={text}
				isOk={isOk}
				AddressListData={addressList}
				addFn={() => { this._selecMap(addressListStr, addressType) }}
				itemRemoveFn={this._removeAddress} />
		)
	}

	// 删除一条数据
	_removeAddress = (index, addressData, str) => {
		if (str == '出库地') {
			this.sendData.srcAddressId = null;
			this.deliveryAddressList = [];
		} else {
			this.sendData.destAddressId = null;
			this.endAddressList = [];
		}
		this.setState({
			ls: true
		})
	}

	//选择出库地点
	_selecMap (str, str2) {

		let { tCode, orderType } = this.orderFlag;
		let { companyId, deliveryType, agencyCompanyId, oppoDeliveryType } = this.sendData;
		let { agencyCompanyName, companyName } = this.state;
		let { companyIdBuy, companyNameBuy } = this.props.navigation.state.params;
		// 如果是背靠背
		if (tCode === 'C') {
			let lsCompanyId = companyIdBuy;
			let lsCompanyName = companyNameBuy;
			// 供应商配送 和 化销目的地  
			if (oppoDeliveryType == '1') {
				lsCompanyId = companyId;
				lsCompanyName = companyName;
			} else if (str2 == 'destAddressId' && oppoDeliveryType == '4') {
				lsCompanyId = companyId;
				lsCompanyName = companyName;
			}
			this.props.navigation.navigate('DeliveryAddress', {
				companyId: lsCompanyId,
				companyName: lsCompanyName,
				oppoDeliveryType: oppoDeliveryType,
				orderType: orderType,
				addressType: str2,  // destAddressId  ->  目的地   DEL ->  出库地
				tCode: tCode,
				getAddressCallBack: (data) => {
					this._addressCallBack(data, str)
				}
			});
		} else {
			companyId = companyId;
			// 代理的发货地址，id取泉州石化
			if (tCode == 'A' && str2 == "DEL") {
				companyId = agencyCompanyId;
				companyName = agencyCompanyName;
			}
			this.props.navigation.navigate('DeliveryAddress', {
				companyId,
				companyName,
				deliveryType: deliveryType,
				orderType: orderType,
				addressType: str2,  // END  ->  目的地   DEL ->  出库地
				tCode: tCode,
				getAddressCallBack: (data) => {
					this._addressCallBack(data, str)
				}
			});
		}
	}

	// 回填地址
	_addressCallBack = (data, str) => {
		if (!data.length) return;
		this[str] = data;
		if (str == 'deliveryAddressList') {
			this.sendData.srcAddressId = data[0].addrId;
		} else {
			this.sendData.destAddressId = data[0].addrId;
		}
		this.setState({
			ls: true
		})
	}

	//运输方式
	_transportTypeCallBack = (index) => {
		this.setState({
			transportTypeValue: this.transportTypeData[index].dictName,
			transportTypeIndex: index
		}, () => {
			this.sendData.transportType = this.transportTypeData[index].dictKey;
			this.closeModal();
		})
	}

	//运输单价 - 输入
	_logisticsPrice = (str) => {
		this.sendData.logisticsPrice = str;
	}

	//render layout
	render () {
		let { status, modalObj } = this.state;
		let { tCode, titleName, currStep } = this.orderFlag;

		return (<View style={orderFormStyle.container}>
			<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : null} keyboardVerticalOffset={20} >
				<ScrollView showsVerticalScrollIndicator={false} keyboardShouldPersistTaps={'handled'}>
					<Common type="headCloes" callBack={this._headCloes} />
					<TitleView title={titleName} describe={'基本信息'} />
					<View style={{ paddingBottom: 100 * scale }}>
						{//长约执行
							tCode ? tCode === 'E' || tCode === 'QH' ? this._rExcuteForm() : this._rNormalForm() : null
						}
					</View>
				</ScrollView>
			</KeyboardAvoidingView>
			{tCode === 'C' && currStep === 2 ? <AddLongBtn callBack={this._headCloes} direction="left" text="上一步" bottom="20" colorBg={style.color.ceruleanUp} /> : null}
			<AddLongBtn callBack={() => {
				this.submitData();
			}} text="下一步" bottom="20" colorBg={style.color.cerulean} />
			{
				status == 'loading' ? (<View style={{ position: 'absolute', height: '100%', width: '100%', top: 0 }}>
					<PageStatusIndex status={status} />
				</View>
				) : null
			}
			<Common type="modal" demoData={(
				<Common type="listRadio" selectIndex={modalObj.currSelectIndex} title={modalObj.currTitle} listData={modalObj.currlistData || []} selectCallBack={modalObj.currCb} />
			)} isVisible={modalObj.currIsVisible} closeCallballFn={this.closeModal} />
		</View >
		)
	}

	_endAddView = () => {
		let { deliveryType, oppoDeliveryType } = this.sendData;
		let { deliveryAddressList, endAddressList } = this;
		let { tCode, currStep, orderType } = this.orderFlag;
		if (tCode == 'C' && !oppoDeliveryType) {
			oppoDeliveryType = deliveryType;
		}
		return (
			<View>
				{/* 选择地址-背靠背模式 */}
				{
					currStep == 2 && tCode === 'C' && oppoDeliveryType && oppoDeliveryType != '1' ? this._renderAddressSelect('出库地', deliveryAddressList, 'deliveryAddressList', 'srcAddressId', oppoDeliveryType == '4' ? '落采合同' : '落采、销合同') : null
				}
				{
					currStep == 2 && tCode === 'C' && (oppoDeliveryType == '1' || oppoDeliveryType == '4') ? this._renderAddressSelect('目的地', endAddressList, 'endAddressList', 'destAddressId', oppoDeliveryType == '4' ? '落销合同' : '落采、销合同') : null
				}



				{/* 选择地址-其他模式 */}
				{/* 采购 */
					tCode != 'QH' && tCode != 'C' && orderType == 'P' ? (
						<View>
							{
								deliveryType && deliveryType != 'S' ? this._renderAddressSelect('出库地', deliveryAddressList, 'deliveryAddressList', 'srcAddressId', deliveryType != 'S' ? '落合同' : false) : null
							}
							{
								(deliveryType && deliveryType != 'U' && deliveryType != 'Q') ? this._renderAddressSelect('目的地', endAddressList, 'endAddressList', 'destAddressId', deliveryType == 'S' ? '落合同' : false) : null
							}
						</View>
					) : null
				}
				{/* 销售 */
					tCode != 'QH' && tCode != 'C' && orderType == 'S' ? (
						<View>
							{
								deliveryType && (deliveryType != 'P') ? this._renderAddressSelect('出库地', deliveryAddressList, 'deliveryAddressList', 'srcAddressId', (deliveryType == 'U' || deliveryType == 'T') ? '落合同' : false) : null
							}
							{
								deliveryType && (deliveryType == 'S' || deliveryType == 'P') ? this._renderAddressSelect('目的地', endAddressList, 'endAddressList', 'destAddressId', (deliveryType == 'P' || deliveryType == 'S') ? '落合同' : false) : null
							}
						</View>
					) : null
				}
				{/* 泉化 */
					tCode == 'QH' ? (
						<View>
							{deliveryType === 'P' || deliveryType === 'S' ? this._renderAddressSelect('目的地', endAddressList, 'endAddressList', 'destAddressId', (deliveryType == 'P' || deliveryType == 'S') ? '落合同' : false) : null}
						</View>
					) : null
				}
				{/* 运输方式 */}
				{
					deliveryType && (deliveryType == 'U' || deliveryType == 'Y') ? this._activeFn2() :
						this._activeFn()
				}
				{/* 运费单价 */}
				{
					tCode == 'QH' ? this._QhYunshu() : this._Yunshu()
				}
			</View>
		)
	}

	_Yunshu = () => {
		let { deliveryType, logisticsPrice, currency } = this.sendData;
		return (deliveryType == 'U' || deliveryType == 'Y') ? null :
			deliveryType ? (<SelectComponent keyboardType="numeric" rightText={CURRENCY.getUnit(currency).text + '/吨'} icon={this.unitSymbol} value={logisticsPrice || '0'} name="运费单价" type='input' inputFn={this._logisticsPrice} />) : null
	}

	_QhYunshu = () => {
		let { deliveryType, logisticsPrice, currency } = this.sendData;
		return (deliveryType == 'T' || deliveryType == 'U') ? null :
			deliveryType ? (<SelectComponent keyboardType="numeric" rightText={CURRENCY.getUnit(currency).text + '/吨'} icon={this.unitSymbol} value={logisticsPrice || '0'} name="运费单价" type='input' inputFn={this._logisticsPrice} />) : null
	}

	_activeFn = () => {
		let { tCode } = this.orderFlag;
		let { transportType } = this.sendData;
		let { transportTypeIndex } = this.state;
		this.isVerify.trans = true;
		return (
			<View>
				{tCode == 'QH' ?
					(
						<View style={[orderFormStyle.item, { marginTop: 15 * scale }]}>
							<Text style={orderFormStyle.itenName}>运输方式</Text>
							<Text style={orderFormStyle.itemValue}>{this.getName(this.transportTypeData, transportType)}</Text>
						</View>
					)
					: <SelectComponent callBack={() => { this.beforeModalOpen('选择运输方式', this.transportTypeData, transportTypeIndex, this._transportTypeCallBack) }} name="运输方式" value={this.getName(this.transportTypeData, transportType) || '请选择'} />}
			</View>
		)
	}
	_activeFn2 = () => {
		this.isVerify.trans = false;
		return null
	}

	//长约执行 获取数据字典的dictName
	getName = (data, dictKey) => {
		let resoutName = '';
		data.forEach((item) => {
			if (item.dictKey == dictKey) resoutName = item.dictName;
		})
		return resoutName
	}

	//长约执行 跳转到长约框架列表页
	gotoList = () => {
		if (this.sendData.orderId) return;
		let params = {
			pushIndex: this.data.pushIndex,
			orderType: this.orderFlag.orderType,
			periodType: this.orderFlag.periodType,
		}
		if (this.orderFlag.tCode === 'QH') params.isQhXhXsBiz = 'Y';

		this.jumpPage('LongListPage', params, this.longListCb)
	}

	//长约执行 跳转框架列表回调
	longListCb = async (data, index) => {
		if (this.sendData.orderId) return;
		if (data) {
			this.setState({ status: 'loading' })
			this.deliveryAddressList = []; // 出库地
			this.endAddressList = []; // 目的地
			await this.editInit(data.orderId, true);
			this.setState({ status: 'data' })
			this.data.pushIndex = index;
		}
	}

	//长约执行 泉化
	_rExcuteForm = () => {
		let { onShow, payTypeArr, deliveryIndex, deliveryTypeIsX, isUnite } = this.state;
		let { tradeType, payStyle, payType, lostRender, currencyName, remark, auditRemark, exeEndDateShow, funds,
			deliveryType, lostRateBig, priceTerm, companyName, outOrderPayMethodList, orderId, priceFormulaType } = this.sendData;
		outOrderPayMethodList = outOrderPayMethodList || [];
		let { orderType } = this.orderFlag;
		return (<View>
			<SelectComponent editable={!orderId} type={orderId ? 'input' : ''} callBack={() => { this.gotoList() }} name={`${this.PageText.company}（必填）`} value={companyName || '请选择'} />
			{
				onShow ? (
					<View>
						{this.orderFlag.tCode === 'QH' ? <View style={{ flexDirection: 'row', flexWrap: 'wrap' }}>
							<Text style={orderFormStyle.trust}>客户资金：</Text>
							<Text style={[orderFormStyle.trust, { marginLeft: 2 * scale, marginRight: 5 * scale }]}>￥{CURRENCY.format(funds)}</Text>
						</View> : null}
						{
							orderType == 'S' && this.orderFlag.tCode != 'QH' ? (
								<View style={toggleBtnStyle.listItemActive}>
									<Text style={toggleBtnStyle.keyText}>业务类型</Text>
									{this.businessTypeData && this.businessTypeData.map((item, index) => {
										return <Text onPress={() => { this.toggleBusiness(index, item.dictKey) }} style={isUnite == item.dictKey ? toggleBtnStyle.checkedText : toggleBtnStyle.unCheckText} key={index}>{item.dictName}</Text>
									})}
								</View>
							) : null
						}
						<View style={orderFormStyle.listRow}>
							<View style={orderFormStyle.item}>
								<Text style={orderFormStyle.itenName}>类型</Text>
								<Text style={orderFormStyle.itemValue}>{this.getName(this.tradeTypeData, tradeType)}</Text>
							</View>
							<View style={orderFormStyle.item}>
								<View style={{ flexDirection: 'row' }}>
									<Text style={orderFormStyle.itenName}>{this.PageText.payType}</Text>
									{this.orderFlag.tCode === 'QH' ? null : <TouchableOpacity onPress={this.titleImgCallBack} style={{ paddingLeft: 10 * scale, paddingRight: 10 * scale }}><Image source={titleImgObj}></Image></TouchableOpacity>}
								</View>
								<Text style={orderFormStyle.itemValue}>{this.getName(this.payTypeData, payType)}</Text>
							</View>
						</View>
						<View style={orderFormStyle.listDay}>
							{tradeType !== 'O' && payTypeArr && payTypeArr.map((item, index) => {
								return (<View key={index} style={orderFormStyle.item}>
									<Text style={[orderFormStyle.itenName]}>{item.title}</Text>
									<Text style={[orderFormStyle.itemValue, { marginBottom: 12 * scale }]}>{item.value}{item.text}</Text>
								</View>)
							})
							}
						</View>
						{/* 外贸 */}
						{tradeType == 'O' ? outOrderPayMethodList.map((item, index) => {
							return (<View key={index}>
								<View style={orderFormStyle.listRow}>
									<View style={orderFormStyle.item}>
										<Text style={orderFormStyle.itenName}>付款方式</Text>
										<Text style={orderFormStyle.itemValue}>{item.payMethodName}</Text>
									</View>
									<View style={orderFormStyle.item}>
										<Text style={orderFormStyle.itenName}>付款比例</Text>
										<Text style={orderFormStyle.itemValue}>{item.prepayRateShow}</Text>
									</View>
								</View>
								{item.payExpireDays ? (<View style={orderFormStyle.item}>
									<Text style={orderFormStyle.itenName}>付款期限</Text>
									<Text style={orderFormStyle.itemValue}>{item.payExpireDays}</Text>
								</View>) : null}
							</View>
							)
						}) : <View style={orderFormStyle.item}>
								<Text style={orderFormStyle.itenName}>{this.PageText.payMethod}</Text>
								<Text style={orderFormStyle.itemValue}>{this.getName(this.payMethodData, payStyle)}</Text>
							</View>
						}

						{tradeType === "O" ? <View style={orderFormStyle.listRow}>
							<View style={orderFormStyle.item}>
								<Text style={orderFormStyle.itenName}>价格条款</Text>
								<Text style={orderFormStyle.itemValue}>{this.getName(this.priceTermsData, priceTerm)}</Text>
							</View>
						</View> : null}

						<View style={orderFormStyle.listRow}>
							<View style={orderFormStyle.item}>
								<Text style={orderFormStyle.itenName}>币种</Text>
								<Text style={orderFormStyle.itemValue}>{currencyName}</Text>
							</View>
							<View style={orderFormStyle.item}>
								<Text style={orderFormStyle.itenName}>交货方式</Text>
								{deliveryTypeIsX ? <SelectComponent callBack={() => {
									this.beforeModalOpen('选择交货方式', this.deliveryData, deliveryIndex, this.deliveryCallBack)
								}} value={this.getName(this.deliveryData, deliveryType) || '请选择'} /> : <Text style={orderFormStyle.itemValue}>{this.getName(this.deliveryData, deliveryType)}</Text>}
							</View>
						</View>
						{deliveryType != 'U' && deliveryType != 'Y' ? (<View style={orderFormStyle.listRow}>
							<View style={orderFormStyle.item}>
								<Text style={orderFormStyle.itenName}>运损承担方</Text>
								<Text style={orderFormStyle.itemValue}>{this.getName(this.lossData, lostRender)}</Text>
							</View>
							<View style={orderFormStyle.item}>
								<Text style={orderFormStyle.itenName}>途损率</Text>
								<Text style={orderFormStyle.itemValue}>千分之 {lostRateBig}</Text>
							</View>
						</View>) : null}
						<View style={orderFormStyle.listRow}>
							<View style={orderFormStyle.item}>
								<Text style={orderFormStyle.itenName}>合同备注</Text>
								<Text style={orderFormStyle.itemValue}>{remark}</Text>
							</View>
							{/* <View style={orderFormStyle.item}>
								<Text style={orderFormStyle.itenName}>送审备注</Text>
								<Text style={orderFormStyle.itemValue}>{auditRemark}</Text>
							</View> */}
							{/* {priceFormulaType == 'PRICE_013' ? <View style={orderFormStyle.item}>
								<Text style={orderFormStyle.itenName}>订单失效时间</Text>
								<Text style={orderFormStyle.itemValue}>{exeEndDateShow}</Text>
							</View> : null} */}
						</View>
						{this._endAddView()}
					</View>
				) : null
			}
		</View>)
	}

	//切换贸易类型
	toggleTrade = (index, key) => {
		if (this.sendData.tradeType == key) {
			return;
		}
		if (this.sendData.orderId) {
			ToastUtil.showWarning('订单已生成,不能切换贸易类型')
			return
		}
		if (!this.isfirstToggle) {
			this.clearPageData(key);
			this.traderType(index, key);
			return
		}

		Alert.alert('提示', '切换交易类型会导致当前页面数据清空哦～', [
			{
				text: '取消',
			}, {
				text: '确定切换',
				onPress: () => {
					this.isfirstToggle = false;
					this.clearPageData(key);
					this.traderType(index, key);
				}
			}
		]);
	}

	//切换贸易类型
	toggleBusiness = (index, key) => {
		if (this.sendData.isUnite == key) {
			return;
		}
		this.businessType(index, key);
	}

	//清空页面数据
	clearPageData = (tradeKey) => {
		let { orderId, oppoOrderId, longOrderId } = this.sendData;
		this.sendData = { orderId, oppoOrderId, longOrderId, currency: 'RMB', lostRateBig: '3', contractStandard: 1 };
		let params = {
			agencyCompanyName: '请选择',//代理供应商名称
			companyName: '请选择',	//供应商名称

			payMethodIndex: -1,
			payMethodValue: '请选择',
			payTypeArr: [],// 付款方式后  输入

			//外贸付款方式
			outOrderPayMethodList: [],
			currPayMethodIndex: 0,//当前列表选中项
			currOutPayMethodListIndex: -1,

			deliveryValue: '请选择',
			deliveryIndex: -1,

			lossValue: '请选择',//运损承担方
			lossIndex: -1,

			disputeValue: '请选择',
			disputeIndex: -1,

			priceTermsValue: '请选择',
			priceTermsIndex: -1,

			status: 'data',
			isLostRate: true,  // 控制涂损率
		};

		this.payTypeData = tradeKey === "O" ? this.outPayTypeData : this.inPayTypeData;
		if (tradeKey === "O") {
			// params.payTypeArr = this.payTypeInit(this.payTypeData[0].dictKey);
			this.payTypeCallBack(0)
		} else {
			params.payTypeValue = '请选择';
			params.payTypeIndex = -1;
		}
		this.setState({
			...params
		}, () => {
			this.operateOutPayMethodList();
			this.lossCallBack(1);
		})
	}

	//选择-交易类型
	traderType = (index, key) => {
		this.setState({
			tradeType: key
		}, function () {
			this.sendData.tradeType = key;
		})
	}

	//选择-业务类型
	businessType = (index, key) => {
		this.setState({
			isUnite: key
		}, function () {
			this.sendData.isUnite = key;
		})
	}

	//供应商跳页面
	providerFn = (isAgent) => {
		//编辑状态不可修改供应商
		if (this.state.pageEdit) {
			return
		}
		let params = {
			orderType: this.orderFlag.orderType,
			isAgent,
			type: 'OrderBaseInfoPage',
			queryType: 'ORDER_ADD',
			bizMode: this.orderFlag.tCode === 'C' ? '1' : '0',
			isAll: true
		}

		if (this.orderFlag.tCode === 'C' && this.orderFlag.currStep == 2) {
			let { companyIdBuy, companyNameBuy } = this.props.navigation.state.params;
			params.companyIdBuy = companyIdBuy;   //  判断 (是否同一个公司,选择地址判断)
			params.companyNameBuy = companyNameBuy;
		}
		this.jumpPage('SeachSupplierPage', params, ((selectData) => {
			this.providerCb(selectData, isAgent)
		}))
	}

	//供应商-返回
	providerCb = async (selectData, isAgent) => {
		let { companyName, companyId } = selectData;
		if (isAgent === 'Y') {
			this.sendData.agencyCompanyId = companyId;
			this.setState({
				agencyCompanyName: companyName
			})
			return;
		}
		if (this.sendData.companyId !== companyId) {
			this.setState({ companyName })
			if (this.sendData.orderId) {
				OrderAPIService.goodsDel({ deleteType: 'ORDER', orderId: this.sendData.orderId });
			}
			this.sendData.companyId = companyId;
			await this.trustFn();
			//清空地址
			this.deliveryAddressList = [];
			this.endAddressList = [];
			this.sendData.srcAddressId = null;
			this.sendData.destAddressId = null;
			this.isVerify.startAddress = null;
			this.isVerify.endAddress = null;
			//清空运输方式
			if (this.orderFlag.tCode != 'QH') {
				this.sendData.transportType = null;
				this.isVerify.trans = null;
			}
			//清空运输单价
			this.sendData.logisticsPrice = '0';
			this.setState({ ls: true })
		}

	}

	writeCallBack = (objData) => {
		console.log('objData', objData)
		let { payTypeArr } = this.state;
		let keyStr = objData.name;
		console.log('keyStr', keyStr)
		this.sendData[keyStr] = parseFloat(objData.value);
		payTypeArr && payTypeArr.map(item => {
			if (keyStr === item.name) {
				item.value = objData.value
			}
		})
	}

	//清空付款类型相关数据
	clearPayTypeData = (payTypeArr) => {
		payTypeArr.map(item => {
			this.sendData[item.name] = '';
		})
	}

	//列表 选中一个付款类型  - 且关闭模态框
	payTypeCallBack = (index) => {
		console.log('index-付款类型', index)
		let payTypeArr = this.payTypeData[index] && this.payTypeData[index].comments ? eval(this.payTypeData[index].comments) : [];
		console.log('payTypeArr', payTypeArr)
		this.setState({
			payTypeValue: this.payTypeData[index].dictName,
			payTypeIndex: index,
			payTypeArr,
			trustShow: this.judgeTrust(this.payTypeData[index].dictKey)
		}, () => {
			this.sendData.payType = this.payTypeData[index].dictKey;
			this.clearPayTypeData(payTypeArr);
			this.closeModal();
		})
	}

	//列表选中一个付款方式
	payMethodCallBack = (index) => {
		this.setState({
			payMethodValue: this.payMethodData[index].dictName,
			payMethodIndex: index
		}, () => {
			this.sendData.payStyle = this.payMethodData[index].dictKey;
			this.closeModal();
		})
	}

	//增加或删除付款方式
	operateOutPayMethodList = (isDel, delIndex) => {
		let outOrderPayMethodList = this.state.outOrderPayMethodList || [];
		if (isDel) {
			outOrderPayMethodList.splice(delIndex, 1);
		} else {
			outOrderPayMethodList.push({ dictName: '请选择', payMethodIndex: -1, prepayRateShow: '' });
		}
		this.setState({ outOrderPayMethodList });
	}

	//列表-外贸-选中一个付款方式
	foreignPayMethodCallBack = (index) => {
		let { outOrderPayMethodList, currPayMethodIndex } = this.state;
		let { dictKey, dictName } = this.outPayMethodData[index];
		outOrderPayMethodList[currPayMethodIndex].payMethod = dictKey;
		outOrderPayMethodList[currPayMethodIndex].payMethodName = dictName;
		outOrderPayMethodList[currPayMethodIndex].payMethodIndex = index;
		if (OrderCreactService.isNeedPaymentDays(dictName)) {
			outOrderPayMethodList[currPayMethodIndex].payExpireDays = '';
			outOrderPayMethodList[currPayMethodIndex].isPayMethodDays = true;
		} else {
			outOrderPayMethodList[currPayMethodIndex].isPayMethodDays = false;
		}
		this.setState({
			outOrderPayMethodList: outOrderPayMethodList,
		}, () => {
			this.closeModal();
		})
	}
	//选择-交货方式
	deliveryCallBack = (index) => {
		this.setState({
			deliveryValue: this.deliveryData[index].dictName,
			deliveryIndex: index,
		}, () => {
			this.sendData.deliveryType = this.deliveryData[index].dictKey;
			this.sendData.oppoDeliveryType = this.deliveryData[index].dictKey;
			this.closeModal();
			this.setState({
				isLostRate: this.sendData.deliveryType == 'U' || this.sendData.deliveryType == 'Y' ? false : true,
				transportTypeValue: '',//清空运输方式
				transportTypeIndex: -1//清空运输方式
			})
			//清空地址
			this.deliveryAddressList = [];
			this.endAddressList = [];
			this.sendData.srcAddressId = null;
			this.sendData.destAddressId = null;
			this.isVerify.startAddress = null;
			this.isVerify.endAddress = null;
			//清空运输方式
			if (this.orderFlag.tCode != 'QH') {
				this.sendData.transportType = null;
				this.isVerify.trans = null;
			}
			//清空运输单价
			this.sendData.logisticsPrice = '0';
		})
	}

	//选择-运损承担方
	lossCallBack = (index) => {
		this.setState({
			lossValue: this.lossData[index].dictName,
			lossIndex: index,
		}, () => {
			this.sendData.lostRender = this.lossData[index].dictKey;
			this.closeModal()
		})
	}

	//contractStandard 0非标  1标准
	lostRateCallBack = (index) => {
		if (index == 0) {
			this.sendData.lostRateBig = '';
			this.sendData.contractStandard = 0;
		} else {
			this.sendData.lostRateBig = this.lostRateData[index].dictName
			this.sendData.contractStandard = 1;
		}
		this.setState({
			lostRateIndex: index,
		}, () => {
			this.closeModal()
		})
	}

	//选择-价格条款
	priceTermsCallBack = (index) => {
		this.setState({
			priceTermsValue: this.priceTermsData[index].dictName,
			priceTermsIndex: index,
		}, () => {
			this.sendData.priceTerm = this.priceTermsData[index].dictKey;
			this.closeModal()
		})
	}

	//问号 功能在开发
	titleImgCallBack = () => {
		Alert.alert('提示', `${this.PageText.payType}保证金/定金、款到发货只有授信的企业才能选择该选项,可去申请企业授信`, [
			{
				text: '知道了',
			}, {
				text: '申请授信',
				onPress: () => {
					let { companyId } = this.sendData;
					if (!companyId) {
						ToastUtil.showWarning(`请先选择${this.PageText.company}`);
						return
					}
					this.props.navigation.navigate('CreditFormPage', { companyId, orderType: this.orderFlag.orderType })
				}
			}
		])
	}

	//途损率
	lostRate = (str) => {
		this.sendData.lostRateBig = str;
	}

	lostRateBlur = (str) => {
		if (!str) return;
		let arr = str.toString().split(".");
		if (arr.length > 1) {
			ToastUtil.showWarning('途损率不能带小数');
			if (timer) {
				clearTimeout(timer)
			}
			timer = setTimeout(() => {
				this.sendData.lostRateBig = arr[0];
			}, 50)
			return
		}
	}

	//合同备注
	remarkFn = (str) => {
		this.sendData.remark = str;
	}

	//送审备注
	auditRemarkFn = (str) => {
		this.sendData.auditRemark = str;
	}
	currencyFn = (dictKey) => {
		this.sendData.currency = dictKey;
		this.setState({ ls: true });
	}
	// '选择运损承担方', this.disputeData, lossIndex, this.lossCallBack
	beforeModalOpen (title, listData, index, cb) {
		if (!this.checkCompany()) { return }
		let { modalObj } = this.state;
		modalObj.currIsVisible = true;
		modalObj.currSelectIndex = index;
		modalObj.currTitle = title;
		modalObj.currlistData = listData;
		modalObj.currCb = cb;
		this.setState({ modalObj });
	}

	closeModal = () => {
		let { modalObj } = this.state;
		modalObj.currIsVisible = false;
		this.setState({ modalObj });
	}

	//现货 远期 长约 代理 闭口
	_rNormalForm = () => {
		let { tradeType, isUnite, companyName, agencyCompanyName,
			payMethodValue, payMethodIndex,
			payTypeValue, payTypeIndex, payTypeArr,
			outOrderPayMethodList,
			deliveryValue, deliveryIndex,
			lossValue, isLostRate, lossIndex,
			priceTermsValue, priceTermsIndex, pageEdit, trustShow,
			lostRateIndex
		} = this.state;
		outOrderPayMethodList = outOrderPayMethodList || [];
		let { limitAmount, creditEndDate, isExpired } = this.showData;
		let { tCode, currStep, orderType } = this.orderFlag;
		let timeStamp = new Date().getTime();
		return <View>
			<View style={toggleBtnStyle.listItemActive}>
				<Text style={toggleBtnStyle.keyText}>交易类型</Text>
				{this.tradeTypeData && this.tradeTypeData.map((item, index) => {
					//只有长约框架的采购---才有外贸
					if (tCode === 'L' && orderType == 'P') {
						if (pageEdit) {
							return tradeType == item.dictKey ? <Text style={toggleBtnStyle.checkedText} key={index}>{item.dictName}</Text> : null
						} else {
							return <Text style={tradeType == item.dictKey ? toggleBtnStyle.checkedText : toggleBtnStyle.unCheckText} key={index} onPress={() => { this.toggleTrade(index, item.dictKey) }} >{item.dictName}</Text>
						}
					} else if (item.dictKey == "I") {
						return <Text style={tradeType == item.dictKey ? toggleBtnStyle.checkedText : toggleBtnStyle.unCheckText} key={index}>{item.dictName}</Text>
					}
				})}
			</View>
			{
				orderType == 'S' && tCode != 'C' ? (
					<View style={toggleBtnStyle.listItemActive}>
						<Text style={toggleBtnStyle.keyText}>业务类型</Text>
						{this.businessTypeData && this.businessTypeData.map((item, index) => {
							return <Text onPress={() => { this.toggleBusiness(index, item.dictKey) }} style={isUnite == item.dictKey ? toggleBtnStyle.checkedText : toggleBtnStyle.unCheckText} key={index}>{item.dictName}</Text>
						})}
					</View>
				) : null
			}
			{tCode === 'A' ? <SelectComponent editable={!pageEdit} type={pageEdit ? 'input' : ''} callBack={() => { this.providerFn('Y') }} name={'供应商'} value={agencyCompanyName} /> : null}
			<View style={{ position: 'relative' }}>
				{pageEdit ? null : <Text style={[orderFormStyle.trust, { position: 'absolute', right: 0, top: 8 * scale, fontSize: 12 * scale }]}>*谨慎修改，会导致填写的相关信息清空</Text>}
				<SelectComponent editable={!pageEdit} type={pageEdit ? 'input' : ''} callBack={() => { this.providerFn() }} name={`${this.PageText.company}（必填）`} value={companyName} />
			</View>
			<SelectComponent name={this.PageText.payType} value={payTypeValue}
				titleImg={true}
				titleImgCallBack={this.titleImgCallBack}
				type={tradeType == 'O' ? 'input' : ''}
				editable={tradeType !== 'O'}
				callBack={() => {
					if (tradeType === 'O') { return; }
					this.beforeModalOpen(`选择${this.PageText.payType}`, this.payTypeData, payTypeIndex, this.payTypeCallBack)
				}} />
			{trustShow ? <View style={{ flexDirection: 'row', flexWrap: 'wrap' }}>
				<Text style={orderFormStyle.trust}>授信可用金额</Text>
				<Text style={[orderFormStyle.trust, { marginLeft: 2 * scale, marginRight: 5 * scale }]}>￥{CURRENCY.format(limitAmount)}</Text>
				{
					isExpired == '2' ? (<Text style={[orderFormStyle.trust, { marginRight: 2 * scale }]}>账户已过期</Text>) : (creditEndDate ? (<View style={orderFormStyle.billText}><Text style={[orderFormStyle.trust, { marginRight: 2 * scale }]}>有效期至</Text><Text style={orderFormStyle.trust}>{creditEndDate || ''}</Text></View>) : null)
				}
			</View> : null}
			<View style={orderFormStyle.listDay}>
				{tradeType !== 'O' && payTypeArr.map((item, index) => {
					return <View key={index}>
						{((item.name === 'payExpireDays' && orderType === 'S') || (item.name === 'deliveryExpireDays' && orderType === 'P')) && trustShow ? <Text style={orderFormStyle.accountDay}>账期:{this.accountDay || 0}天</Text> : null}
						<HalfList key={timeStamp + index} keyboardType='numeric' title={item.title} name={item.name} value={item.value} text={item.text} writeCallBack={this.writeCallBack} />
					</View>
				})}
			</View>

			{tCode === 'L' && tradeType == 'O' ? <Text style={orderFormStyle.addPayment} onPress={() => { this.operateOutPayMethodList() }}>添加付款方式</Text> : null}
			{tCode === 'L' && tradeType == 'O' ? outOrderPayMethodList.map((item, index) => {
				return <View key={index}>
					<View style={{ flexDirection: 'row', position: 'relative', justifyContent: 'space-between' }}>
						<Text onPress={() => { this.operateOutPayMethodList(true, index) }} style={orderFormStyle.delPayment}>删除</Text>
						<View style={{ width: '45%' }}>
							<SelectComponent callBack={() => {
								this.setState({ currPayMethodIndex: index, currOutPayMethodListIndex: item.payMethodIndex }, () => {
									this.beforeModalOpen(`选择付款方式`, this.outPayMethodData, payMethodIndex, this.foreignPayMethodCallBack)
								})
							}} name="付款方式" value={item.payMethodName} />
						</View>
						<View style={{ width: '45%' }}>
							<SelectComponent type='input' keyboardType='numeric' name='付款比例' rightText='%' value={item.prepayRateShow} inputFn={(str) => {
								item.prepayRateShow = str
							}} />
						</View>
					</View>
					{item.isPayMethodDays ? <View style={{ width: '45%', position: 'relative' }} >
						<SelectComponent type='input' keyboardType='numeric' name='付款期限' rightText='天' value={item.payExpireDays} inputFn={(str) => {
							item.payExpireDays = str
						}} />
					</View> : null}
				</View>
			}) : <SelectComponent callBack={() => { this.beforeModalOpen(`选择${this.PageText.payMethod}`, this.payMethodData, payMethodIndex, this.payMethodCallBack) }} name={this.PageText.payMethod} value={payMethodValue} />}
			{tCode === 'L' && tradeType == 'O' ? <SelectComponent callBack={() => { this.beforeModalOpen(`选择价格条款`, this.priceTermsData, priceTermsIndex, this.priceTermsCallBack) }} name={'价格条款'} value={priceTermsValue} /> : null}
			{tCode === 'L' && tradeType == 'O' ? <View>
				<Text style={orderFormStyle.currencyType}>币种</Text>
				<View style={{ flexDirection: 'row' }}>
					{OrderCreactService.CURRENCY_ENUM.map((item, index) => {
						let statusImage = item.dictKey === this.sendData.currency ? statusOn : statusOff;
						return <TouchableOpacity style={{ flexDirection: 'row' }} onPress={() => { this.currencyFn(item.dictKey) }} key={index}>
							<Image style={{ marginRight: 15 * scale, }} source={statusImage} />
							<Text style={{ marginRight: 25 * scale, height: 19 * scale, lineHeight: 19 * scale }} >{item.dictName}</Text>
						</TouchableOpacity>
					})}
				</View>
			</View> : null}

			{/* 闭口第一步 没有以下字段 */}
			{(currStep !== 1 || tCode !== 'C') ? <View>
				<SelectComponent callBack={() => { this.beforeModalOpen('选择交货方式', this.deliveryData, deliveryIndex, this.deliveryCallBack) }} name="交货方式" value={deliveryValue} />
				{this._endAddView()}
				{isLostRate ? <View style={{ flexDirection: 'row', justifyContent: 'space-between' }}>
					<View style={{ width: '45%' }}>
						<SelectComponent callBack={() => { this.beforeModalOpen('选择运损承担方', this.lossData, lossIndex, this.lossCallBack) }} name="运损承担方" value={lossValue} />
					</View>
					<View style={{ width: '45%', position: 'relative' }}>
						<TouchableOpacity style={orderFormStyle.lostRate} onPress={() => { this.beforeModalOpen('途损率', this.lostRateData, lostRateIndex, this.lostRateCallBack) }}>
							<Image source={arrowImg} style={{ transform: [{ 'rotate': '90deg' }], height: 12 * scale }} />
							<Text style={orderFormStyle.standard}>{this.sendData.contractStandard == 0 ? '非标' : '标准'}</Text>
						</TouchableOpacity>
						<SelectComponent
							inputFn={this.lostRate}
							type='input'
							editable={this.sendData.contractStandard == 0}
							rightText="千分之" keyboardType='numeric' name="途损率"
							value={this.sendData.lostRateBig} />
					</View>
				</View> : null}
				<SelectComponent inputFn={this.remarkFn} maxLength={500} type="input" keyboardType='default' name="合同备注" value={this.sendData.remark} />
				<SelectComponent inputFn={this.auditRemarkFn} maxLength={200} type="input" keyboardType='default' name="送审备注" value={this.sendData.auditRemark} />
			</View> : null}
		</View>
	}
}
